<template>
	<view>
		<view class='list_con'>
			<mescroll-uni :down="downOption" @down="downCallback" @up="upCallback">
				<view></view>
				<view class='orderList' v-for="(item,index) in dataList" :key="index">
					<view class='headpic_list'></view>
					<view class='left_orderList'>
						<!-- 1:分享收益；2:店铺收益；3:代理商收益；-1:退还分享收益；-2:退还店铺收益；-3:退还代理商收益 -->
						<text class='title_orderList' v-if="item.type==1">分享收益</text>
						<text class='title_orderList' v-if="item.type==2">店铺收益</text>
						<text class='title_orderList' v-if="item.type==3">代理商收益</text>
						<text class='title_orderList' v-if="item.type==-1">退还分享收益</text>
						<text class='title_orderList' v-if="item.type==-2">退还店铺收益</text>
						<text class='title_orderList' v-if="item.type==-3">退还代理商收益</text>
					</view>
					<view class='right_orderList'>
						<view class='pre_money'>
							<text class='money_budget'>{{numFilter(item.profit)}}</text>
						</view>
					</view>
					<view class='leaseDateArea'>
						<view class='pre_leaseDate'>
							<text class='lable_leaseDate'>日期：</text>
							<text class='leaseDate'>{{item.create_time}}</text>
						</view>
					</view>
				</view>
				
			</mescroll-uni>  
			
		</view>
		<text class='notice_nodata' v-if='noticeShow'>暂无数据</text>	
	</view>
</template>

<script>
	import http from '../../../common/http.js'
	import common from '../../../common/common.js'
	import config from '../../../common/config.js'
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue";
	import uniSwiperDot from '@/components/uni-swiper-dot/uni-swiper-dot.vue';
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue'
	import uniStatusBar from '@/components/uni-status-bar/uni-status-bar.vue'
	export default {
		components: {
			uniIcons,
			uniNavBar,
			uniStatusBar,
			uniSwiperDot,
			MescrollUni
		},
		data() {
			return {
				 textStatue:"#fb4343",
				 overtime:false,
				 page:1,
				 pageSize:20,
				 // 下拉刷新的常用配置
				 downOption: { 
				 	use: true, // 是否启用下拉刷新; 默认true
				 	auto: true, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
				 },
				 // 上拉加载的常用配置
				 upOption: {
				 	use: true, // 是否启用上拉加载; 默认true
				 	auto: true, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
				 	page: {
				 		num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
				 		size: 10 // 每页数据的数量,默认10
				 	},
				 	noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				 	empty: {
				 		tip: '暂无相关数据'
				 	}
				 },
				 // 列表数据
				 dataList: [],
				 curPageLength:0,
			}
		},
		onLoad() {
			
		},
		methods: {
			numFilter (value) {//收益数计算
			  let realVal = ''
			  if (value) {
			    // 截取当前数据到小数点后两位
			    realVal = parseFloat(value)/100;
							  realVal = realVal.toFixed(2);
			  } else {
			    realVal = '0'
			  }
			  return realVal
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			/*下拉刷新的回调 */
				downCallback(mescroll) {
					//联网加载数据
					this.getListDataFromNet(0, 1, (data) => {
						//联网成功的回调,隐藏下拉刷新的状态
						mescroll.endSuccess();
						//设置列表数据
						this.dataList.unshift(data[0]);
					}, () => {
						//联网失败的回调,隐藏下拉刷新的状态
						mescroll.endErr();
					})
				},
				/*上拉加载的回调: mescroll携带page的参数, 其中num:当前页 从1开始, size:每页数据条数,默认10 */
				upCallback(mescroll) {
					//联网加载数据
					this.getListDataFromNet(mescroll.num, mescroll.size, (curPageData)=>{
									mescroll.endSuccess(curPageData.length);
						//设置列表数据
						this.dataList=this.dataList.concat(curPageData);
					}, () => {
						//联网失败的回调,隐藏下拉刷新的状态
						mescroll.endErr();
					})
				},
				async getListDataFromNet(pageNum, pageSize, successCallback, errorCallback) {
					 var that =this;
					 try {
						if (pageNum == 0) {
							//此处模拟下拉刷新返回的数据
							let params = {
									appid:common.appid,
									api_version:common.apiversion,
									timestamp:common.timesTamp,
									token:uni.getStorageSync("userToken"),
									page:1,
									page_size:this.pageSize
									
								};
							   let signStr = common.sign(params);
							   params.sign = signStr;
							   await uni.request({
									 url:config.assembleUrl+'group/profit/list', 
									 method:"POST",
									 header:{
										 'content-type':'application/x-www-form-urlencoded',
										  },
									data: params,
									 success: function (res) {
										 var lists =res.data.data.list;
										 if((lists=="")||(lists==undefined)||(lists==[])){
										 		that.noticeShow = true;
										  }else{
										 		that.noticeShow = false; 
										  }
										 if(pageNum == 1)
										 that.dataList = []; //如果是第一页需手动置空列表
										 that.dataList = that.dataList.concat(lists);
									 }
								 });
							
						
						} else {
							//此处模拟上拉加载返回的数据
							let params = {
									appid:common.appid,
									api_version:common.apiversion,
									timestamp:common.timesTamp,
									token:uni.getStorageSync("userToken"),
									page:this.page,
									page_size:this.pageSize
								};
							   let signStr = common.sign(params);
							   params.sign = signStr;
							   await uni.request({
									 url:config.assembleUrl+'group/profit/list', 
									 method:"POST",
									 header:{
										 'content-type':'application/x-www-form-urlencoded',
										  },
									data: params,
									 success: function (res) {
										var lists =res.data.data.list;
										 if(pageNum == 1)
										 that.dataList = []; //如果是第一页需手动置空列表
										 that.dataList = that.dataList.concat(lists);
									 }
								 });
						}
							//联网成功的回调
							successCallback && successCallback(that.dataList);
						} catch (e) {
							//联网失败的回调
							errorCallback && errorCallback();
						}
									
				}
							
							
							
		}
		
	}
</script>

<style>
	.list_con{
		width:100%;
		height:auto;
		margin-top:1px;
	}
	.orderList{
		width:100%;
		height:auto;
		float:left;
		background:#fff;
		padding:3% 0 1% 0;
	}
	.left_orderList{
		width:52%;
		height:auto;
		float:left;
		margin-left:3%;
	}
	.right_orderList{
		width:22%;
		height:auto;
		float:right;
		margin-right:3%;
	}
	.title_orderList{
		width:100%;
		min-height:18px;
		float:left;
		margin-bottom:5px;
		font-size:1.1em;
		line-height:22px;
		font-weight:600;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	.pre_leaseDate{
		width:100%;
		height:24px;
		float:left;
		padding-left:55px;
		color:#8e8d8d;
		border-bottom:solid 1px #efefef;
		
	}
	.pre_leaseDate text{
			width:auto;
			height:24px;
			line-height:24px;
			
		}
	.statue_orderList{
		width:20%;
		height:24px;
		float:right;
		color:#8e8d8d;
		text-align: right;
		
	}
	.statue_orderList text{
			width:auto;
			height:24px;
			line-height:24px;
			
		}
	.leaseDateArea{
		width:94%;
		height:auto;
		float:left;
		margin-left:3%;
	}
	.headpic_list{
		width:46px;
		height:46px;
		float:left;
		background:url(../../../static/sp.png)no-repeat;
		background-size:100% 100%;
		margin-left:3%;
		border-radius: 5px;
	}
	.money_budget{
		float:right;
		font-weight: 600;
	}
	.pre_money_statue{
		width:100%;
		float:left;
		margin-top:3px;
	}
	.money_statue{
		float:right;
		padding:2px 3px;
		background:rgba(254,244,239,0.8);
		color:#eb6c37;
	} 
	.notice_nodata{
		width:100%;
		color:#979797;
		position: absolute;
		top:200px;
		font-size:1.1em;
		text-align: center;
	}
</style>
